var editor;
KindEditor.ready(function(K) {
			 editor = K.create('textarea[name="content"]', {
				cssPath : 'js/kindeditor/plugins/code/prettify.css',
				uploadJson : 'js/kindeditor/jsp/upload_json.jsp',
				fileManagerJson : 'js/kindeditor/jsp/file_manager_json.jsp',
				allowFileManager : true,
				afterCreate : function() {
					var self = this;
					K.ctrl(document, 13, function() {
						self.sync();
						document.forms['mailForm'].submit();
					});
					K.ctrl(self.edit.doc, 13, function() {
						self.sync();
						document.forms['mailForm'].submit();
					});
				}
			});
			prettyPrint();
		});
function selectUser(val){
		var url="mailGroupUser.action?status="+val;
		openWindow(url,700,420);
	}

function setValue(value,val){
  var arr = eval(value);
  var names = "";
  var ids = "";
  for(i=0;i<arr.length;i++){
    ids =  ids + "," + arr[i].value;
    names = names + "," + arr[i].name;
  }
  if(names.length>0){
    names = names.substring(1);
    ids =  ids.substring(1);
  }
  document.getElementById(val+"names").value=names;
  document.getElementById(val+"ids").value=ids;
}

function getOldValue(val){
  var ids=document.getElementById(val+"ids").value;
  var names=document.getElementById(val+"names").value;
    var array="";
  if(ids!=''&&ids!='null'){
  var idarray=ids.split(",");
  var namearray=names.split(",");
  for(var i=0;i<idarray.length;i++){
  		if(i==0){
  			array+="{\"value\":"+idarray[i]+",\"name\":\""+namearray[i]+"\"}";
  		}else{
  	      array+=",{\"value\":"+idarray[i]+",\"name\":\""+namearray[i]+"\"}";
  	   } 
  }
  }
  return array;
}
	function valiadValue(value){
		var names=$("#snames").val();
		var title=$("#title").val();
		var sHTML = editor.html();
		var sids=$("#sids").val();
		var cids=$("#cids").val();
		var mids=$("#mids").val();
		if(value!='draft'){
			if($.trim(names)==''||$.trim(name)=='null'){
				alert("收件人不能为空！");
				return;
			}
		}
		if($.trim(sids)!=''&&$.trim(cids)!=''){
			var sidsArr=sids.split(",");
			var cidsArr=cids.split(",");
			for(var i=0;i<sidsArr.length;i++){
				for(var j=0;j<cidsArr.length;j++){
					if(sidsArr[i]==cidsArr[j]){
						alert("收件人和抄送人不能重复！");
						return;
					}
				}
			}
			}
			if($.trim(sids)!=''&&$.trim(mids)!=''){
			var sidsArr=sids.split(",");
			var midsArr=mids.split(",");
			for(var i=0;i<sidsArr.length;i++){
				for(var j=0;j<midsArr.length;j++){
					if(sidsArr[i]==midsArr[j]){
						alert("收件人和密送人不能重复！");
						return;
					}
				}
			}
			}
			if($.trim(mids)!=''&&$.trim(cids)!=''){
			for(var i=0;i<midsArr.length;i++){
				for(var j=0;j<cidsArr.length;j++){
					if(midsArr[i]==cidsArr[j]){
						alert("抄送人和密送人不能重复！");
						return;
					}
				}
			}
		}
		if($.trim(title)==''||$.trim(title)=='null'){
			alert("主题不能为空！");
			return ;
		}
		$("#content").val($.trim(sHTML));
		$("#sendButton").attr("disabled","true");
		
		if(value=='draft'){
			document.mailForm.action="saveGraftMail.action";
		}else if(value=='send'){
			document.mailForm.action="saveInMail.action";
		}
		var table=$("#filetable").find("input[type=\"checkbox\"]");
		var fileId="";
		for(var i=0;i<table.length;i++){
			fileId+="_"+table[i].value;
		}
		$("#fileArray").val(fileId);
		document.mailForm.submit();
	}
	